<template>
  <div class="nav-box">
    <div class="nav-title">{{ title }}</div>
    <div class="nav-right">
      <i class="fa fa-bars" aria-hidden="true"></i>
      <!-- 下拉菜单 -->
      <el-dropdown trigger="click" @command="linkout">
        <span class="el-dropdown-link">
          <span>{{ userName }}</span
          ><i class="el-icon-arrow-down el-icon--right"></i>
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item icon="fa fa-sign-out" command="0"
            >退出</el-dropdown-item
          >
          <el-dropdown-item icon="fa fa-hand-o-right" command="1"
            >首页</el-dropdown-item
          >
        </el-dropdown-menu>
      </el-dropdown>
    </div>
  </div>
</template>

<script>
export default {
  name: "Header",
  props: ["title"],
  computed: {
    userName() {
      let userInfo = JSON.parse(window.sessionStorage.getItem("token"));
      return userInfo.Username;
    },
  },
  methods: {
    linkout(idx) {
      // 0 是退出  1 是首页
      if (Number(idx)) {
        this.$router.push("/pageindex");
      } else {
        this.$router.push("/login");
        window.sessionStorage.clear();
      }
    },
  },
};
</script>

<style lang="less" scoped>
// 头部
.nav-box {
  .nav-title {
    width: 200px;
    height: 100%;
    padding: 0 10px;
    background: #196a98;
    font-size: 18px;
    color: #fff;
    float: left;
    text-align: center;
    line-height: 60px;
  }
  .nav-right {
    height: 100%;
    background: #3d8fbc;
    line-height: 60px;
    padding: 0 30px 0 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    i {
      color: #7fafc6;
    }
    .el-dropdown > span {
      span,
      i {
        color: #fff;
      }
    }
  }
}
</style>
